package org.sws.domain.behavior.strategy.impl;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.sws.domain.behavior.event.SendRebateMessageEvent;
import org.sws.domain.behavior.strategy.RebateStrategy;
import org.sws.domain.credit.model.entity.TradeEntity;
import org.sws.domain.credit.model.valobj.TradeNameVO;
import org.sws.domain.credit.model.valobj.TradeTypeVO;
import org.sws.domain.credit.service.ICreditAdjustService;

import java.math.BigDecimal;

/**
 * @Author sws
 * @Date 2025/4/1 16:36
 * @description: 积分返利策略实现类
 */
@Service(value = "integral")
@RequiredArgsConstructor
public class IntegralRebateStrategy implements RebateStrategy {

    private final ICreditAdjustService creditIncreaseService;
    @Override
    public String handleRebate(SendRebateMessageEvent.RebateMessage rebateMessage) {
        TradeEntity tradeEntity = new TradeEntity();
        tradeEntity.setUserId(rebateMessage.getUserId());
        tradeEntity.setTradeName(TradeNameVO.REBATE);
        tradeEntity.setTradeType(TradeTypeVO.FORWARD);
        tradeEntity.setAmount(new BigDecimal(rebateMessage.getRebateConfig()));
        tradeEntity.setOutBusinessNo(rebateMessage.getBizId());
        return creditIncreaseService.createCreditOrder(tradeEntity);
    }
}
